package com.china08.yxyapi.api.manage.tec.teaching.homework.worklist.workcorrect1;

import java.text.ParseException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.mg.homework.HomeworkTaskReport;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskReportRepository;

/**
 * 修改学生的评语
 */
@CrossOrigin
@RestController
public class Workcorrect1UpdRemarkController {

    @Autowired
    HomeworkTaskReportRepository homeworkTaskReportRepository;

    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/tec/teaching/homework/worklist/workcorrect1/stu/remark/upd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(//
            HttpServletRequest request, //
            HttpServletResponse response, //
            @RequestBody ReqModel reqModel, //
            RespModel respModel) throws ParseException {

        // 获取学生
        HomeworkTaskReport homeworkTaskReport = homeworkTaskReportRepository
                .findByStudentIdAndTaskId(reqModel.studentId, reqModel.taskId);
        // update
        homeworkTaskReport.setEvaluate(reqModel.remark);
        homeworkTaskReportRepository.save(homeworkTaskReport);

        return respModel;
    }

    /** 请求参数 */
    public static class ReqModel extends YxyApiReqModel {
        // 任务Id
        public String taskId;
        // 学生Id
        public String studentId;
        // 评语 remark
        public String remark;
    }

    /** 响应 */
    public static class RespModel extends YxyApiRespModel {
    }
}
